package com.nj.liandi.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.nj.liandi.gulimall.order.config.AlipayTemplate;
import com.nj.liandi.gulimall.order.service.OrderService;
import com.nj.liandi.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * description: 接受支付请求
 * date: 2021/11/8 11:09
 * author: maizj
 * version: 1.0
 */
@Controller
public class PayWebController {

    @Autowired
    AlipayTemplate alipayTemplate;

    @Autowired
    OrderService orderService;
    
    /** description: 跳转支付页面
     * version: 1.0 
     * date: 2021/11/8 11:11
     * */
    @ResponseBody
    @GetMapping(value = "/payOrder",produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getOrderPay(orderSn);
        String pay = alipayTemplate.pay(payVo);
        System.out.println("=="+pay);
        return pay;
    }
}
